﻿@model IEnumerable<Sys_User>
@{
    var tableId = "listTable";
    ///#listTable .checkboxes
    var checkboxDataSet = string.Format("#{0} .checkboxes", tableId);
    var list = ViewBag.Columns as List<string>;
    var count = (list?.Count).GetValueOrDefault();

    var downloadUrl = Url.Action("Download");

    //是不是應該實現一個東西判斷輸入的數據為空的時候直接跳轉到錯誤頁面呢
}
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet box blue">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-globe"></i>@ViewBag.TableTitle
                </div>
                <div class="actions">
                    <div class="btn-group">
                        <a class="btn default" href="#" data-toggle="dropdown">
                            Columns <i class="fa fa-angle-down"></i>
                        </a>
                        <div id="sample_2_column_toggler" class="dropdown-menu hold-on-click dropdown-checkboxes pull-right">
                            @*打印标题栏*@
                            @for (var i = 0; i < count; i++)
                            {
                                <label>
                                    <input type="checkbox" checked data-column="@i">@list[i]
                                </label>
                            }
                        </div>
                    </div>
                </div>
            </div>
            <div class="portlet-body">
                <table class="table table-striped table-bordered table-hover table-full-width" id="@tableId">
                    <thead>
                        <tr>
                            <th class="table-checkbox sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="" style="width: 20px;">
                                <div class="checker">
                                    <span class=""><input type="checkbox" class="group-checkable" data-set="@checkboxDataSet"></span>
                                </div>
                                <a class="btn default btn-xs black" onclick="deleteList()">
                                    <i class="fa fa-trash-o"></i>
                                </a>
                            </th>
                            @*打印标题栏*@
                            @for (var i = 0; i < count; i++)
                            {
                                <th>@list[i]</th>
                            }
                        </tr>
                    </thead>
                    <tbody>
                        @*打印数据*@
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td class="sorting_@item.Id">
                                    <div class="checker">
                                        <span class=""><input type="checkbox" class="checkboxes" value="@item.Id"></span>
                                    </div>
                                </td>
                                <td class="center">
                                    @item.LoginName
                                </td>
                                <td class="center">
                                    @item.Name
                                </td>
                                <td class="center">
                                    <a href="@Url.Action("Edit", new {item.Id})" class="btn default btn-xs purple"><i class="fa fa-edit"></i> Edit</a>
                                    <a href="@Url.Action("Delete", new {item.Id})" class="btn default btn-xs black"><i class="fa fa-trash-o"></i> Delete</a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
</div>

@section script{
    <script src="~/assets/zrjs/user/list.js"></script>
    <script>
        $(function () {
            window.deleteUrl = "@Url.Action("Delete")";
            TableAdvanced.init('@tableId');
        });

        function deleteList() {
            var arr = [];
            $('@checkboxDataSet:checked')
                .each(function (i, e) {
                    arr.push($(e).val());
                });

            var data = { "ids": arr };

            $.post(deleteUrl,
                data,
                function (result) {
                    msgBox.showMsg(result);
                    comm.ajaxSuccess(result);
                },
                "json");
        }
    </script>
}